package com.fallsvc.re.javasesets.carraylistlinkedlist;

import java.util.*;

public class Demo1 {

    public static void main1(String[] args) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.reverse();

        Vector<Integer> vector = new Vector<>();
        vector.add(10);
        vector.add(20);
        vector.set(1,30);
        vector.insertElementAt(20,1);
        Collections.reverse(vector);
        System.out.println(vector);
    }

    public static void main2(String[] args) {
        Random random = new Random(20190905);
        for (int i = 0; i < 10 ; i++) {
            System.out.println(random.nextInt(2));
        }

        Stack<Integer> s = new Stack<>();
        Set<Integer> set = new HashSet<>();
        System.out.println(set.add(1));
        System.out.println(set.add(1));
    }

    public static void main(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        // 使用迭代器遍历---正向遍历
        ListIterator<Integer> it = list.listIterator();
        while(it.hasNext()){
            System.out.print(it.next()+ " ");
        }
        System.out.println();
// 使用反向迭代器---反向遍历
        ListIterator<Integer> rit = list.listIterator(list.size());
        while (rit.hasPrevious()){
            System.out.print(rit.previous() +" ");
        }
        System.out.println();
    }
}